<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	$return['setting']=$this->plugin_setting('basic');
	$return['list']=array();
	set_html('title',$$basic['title']?$basic['title']:'门店地图');
	$return['params']=array();
	exi($return);
}
// js 获取数据
if($_RQ['op']=='getlist'){
	$params=array(
		'uniacid'=>$_SESSION['uniacid'],
		'merchid'=>0,
		'status'=>1,
	);
	if(trim($_RQ['keyword'])){
		$params['title like']='%'.trim($_RQ['keyword']).'%';
		$return['params']['keyword']=trim($_RQ['keyword']);
	}
	if($_RQ['pcate']){
		$params['pcate']=intval($_RQ['pcate']);
		$return['params']['pcate']=intval($_RQ['pcate']);
	}
	if($_RQ['ccate']){
		$params['ccate']=intval($_RQ['ccate']);
		$return['params']['ccate']=intval($_RQ['ccate']);
	}
	if($_RQ['order']=='isrecommand'){
		$params['saletype likes']=array('1');
		$return['params']['order']='isrecommand';
	}
	if($_RQ['order']=='isnew'){
		$params['saletype likes']=array('2');
		$return['params']['order']='isnew';
	}
	if($_RQ['order']=='ishot'){
		$params['saletype likes']=array('3');
		$return['params']['order']='ishot';
	}
	if($_RQ['priceMin']){
		$params['price >=']=intval($_RQ['priceMin']);
		$return['params']['priceMin']=intval($_RQ['priceMin']);
	}
	if($_RQ['priceMax']){
		$params['price <=']=intval($_RQ['priceMax']);
		$return['params']['priceMax']=intval($_RQ['priceMax']);
	}
	//进一步整理筛选条件，商品属性字段是否需 要调整，商品分类如何筛选，orderby如何整理
	$pindex = max(1, intval($_RQ['page']));
	$psize = 20;
	if($_RQ['num']){
		$psize=$_RQ['num'];
	}
	$total='';
	$fields=array('id','title','subtitle','image','video','price','active_plugin','active_id','salenum','total','pluginname','originalprice');
	$orderby='salenum desc , id desc ';
	if($_RQ['order']){
		if($_RQ['order']=='sales'){
			$orderby='salerealnum desc';
		}
		if($_RQ['order']=='price'){
			if($_RQ['order_type']==2){
				$orderby='price desc';
			}else{
				$orderby='price asc';
			}
			
		}
	}
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'fields'=>$fields,
		'orderby'=>$orderby,
	);
	$list=$this->model('goods')->goods_list($parameter,$total);
	if(!$list){
		exi('none');
	}else{
		foreach($list as &$itemv){
			$itemv['oldtotal']=$itemv['total'];
			$itemv['total']=pdo_getcolumn('jy_weishop_store_goods',array('uniacid'=>$_SESSION['uniacid'],'goodsid'=>$itemv['id'],'storeid'=>$this->store_id),'total');
			$itemv['originalprice']=$itemv['originalprice']>0?$itemv['originalprice']:price($itemv['price']*1.2);
			$itemv['createtime']=$itemv['createtime']?:time()-58*3600*24;
			$itemv['createtime']=date('Y-m-d',$itemv['createtime']);
			//按点赞数排序作品
			$pindex = max(1, 0);
			$psize = 4;
			$members=pdo_getslice('jy_weishop_order_goods',array('uniacid'=>$_SESSION['uniacid'],'goodsid'=>$itemv['id']),array($pindex,$psize),$total,array('mid'),'','id desc');
			foreach($members as &$mv){
				$memberinfo=pdo_get('core_members',array('id'=>$mv['mid']),array('nickname','avatar'));
				$mv['nickname']=$memberinfo['nickname'];
				$mv['avatar']=$memberinfo['avatar'];
			}
			$itemv['members']=$members;
			$itemv['merchname']=pdo_getcolumn('jy_merch_user',array('id'=>$itemv['merchid']),'merchname');
			$itemv['likes']=pdo_count('jy_weishop_member_history',array('uniacid'=>$_SESSION['uniacid'],'goodsid'=>$itemv['id']),'id');
		}
	}
	exi($list);
}
if($_RQ['op']=='settotal'){
	$postdata=get_postdata();
	$id=intval($postdata['id']);
	if(!$id){
		exi('请选择商品','error');
	}
	pdo_update('jy_weishop_store_goods',array('total'=>$postdata['total']),array('goodsid'=>$id,'storeid'=>$this->store_id,'uniacid'=>$_SESSION['uniacid']));
	exi('操作成功！');
}
?>